/**
 * 报价提交数据
 * Created by wujianjin on 2015/7/20.
 */

/**
 * 报价结算表格
 * Created by douxc on 2015/4/21.
 */
define(function (require, exports, module) {
    'use strict';
    module.exports = function (app) {
        app.register.controller('quoteSubmitCtrl', ['$scope', 'MHService','$location',
            function ($scope, MHService,$location) {
                var total = MHService.globalData(false, {key: 'total'});
                var suppliers = MHService.globalData(false, {key: 'supplier'});
                var feed = MHService.globalData(false, {key: 'feed'});
                var materialList = MHService.cacheData(false, {key: 'materialList'});
//                console.log("16",total);
//                console.log("18",suppliers);
//                console.log("19",feed);
//                console.log("19",materialList);
                    $scope.complete = function(){
//                    $scope.description,$scope.quoteName
                        var postUrl = MHService.URL.exportBuildPrice;
                        var reqData = {
//                        mid:1,count:1,price:1,pp:1,ccost:1,rcost:1,allprice:1
                            xc:total.results[0].costs,
                            sj:total.results[1].costs,
                            yxs:total.results[2].costs,
                            mxs:total.results[3].costs,
                            other:total.results[4].costs,
                            hz_sum:total.total,
                            b1:total.results[1].percent,
                            b2:total.results[2].percent,
                            b3:total.results[3].percent,
                            modeArray:"1,"+feed[0]+","+materialList[0].num+","+suppliers.relation.price+","+suppliers.relation.pprice+","+suppliers.relation.cost+","+suppliers.relation.pcost+","+materialList[0].num*materialList[0].price,
                            name:$scope.quoteName,
                            description:$scope.description

                        };
//                        console.log(reqData);
                        MHService.postReq({url:postUrl,_req:reqData}, function (data) {
                            if(data){
                                $location.path("/quote");
                                MHService.Toast('报价提交成功');
                            }else{
                                MHService.Toast('报价提交失败');
                            }

                        });
                    }

            }]);
    };
});
